package com.zw.gulimall.ware.service.impl;

import com.zw.gulimall.utils.R;
import com.zw.gulimall.ware.entity.WareSkuEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zw.gulimall.utils.PageUtils;
import com.zw.gulimall.utils.Query;

import com.zw.gulimall.ware.dao.PurchaseDetailDao;
import com.zw.gulimall.ware.entity.PurchaseDetailEntity;
import com.zw.gulimall.ware.service.PurchaseDetailService;
import org.springframework.util.StringUtils;


@Service("purchaseDetailService")
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailDao, PurchaseDetailEntity> implements PurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<PurchaseDetailEntity> wrapper = new QueryWrapper<>();
        String key = (String)params.get("key");

        String status = (String)params.get("status");
        String wareId = (String)params.get("wareId");
        if (StringUtils.hasText(key)){
            wrapper.and(e->e.eq("purchase_id",key).or().eq("sku_id",key));
        }
        if (StringUtils.hasText(status)){
            wrapper.eq("sku_id",status);
        }
        if (StringUtils.hasText(wareId)){
            wrapper.eq("ware_id",wareId);
        }
        IPage<PurchaseDetailEntity> page = this.page(new Query<PurchaseDetailEntity>().getPage(params), wrapper);

        return new PageUtils(page);
    }

    @Override
    public List<PurchaseDetailEntity> listDetailByPurchaseId(Long id) {

        List<PurchaseDetailEntity> purchaseId = this.list(new QueryWrapper<PurchaseDetailEntity>().eq("purchase_id", id));

        return purchaseId;
    }

}